<html>
<head>
<title>My Form</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>public/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>public/css/bootstrap-theme.min.css">
<script type="text/javascript" src="<?php echo base_url();?>public/js/jquery.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/kindeditor/kindeditor-all-min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/kindeditor/lang/zh-CN.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/js/jquery.upload.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>public/css/style.css">
<script>
	var editor;
	KindEditor.ready(function(K) {
		editor = K.create("#content");
	});	
</script>
</head>
<body>
<?php $this->load->view('admin/admin_nav'); ?>
<div class="container">
	  <h3><?php echo $a;?>文章</h3>
	<div class="row">
		<div class="form-group col-md-9 ">
			<form class="form-horizontal" action="" method="POST">
				<div class="form-group">
					<label class="col-sm-2 control-label">标题：</label>
				    <div class="col-sm-9">
				    	<input type="text" name="title" class="form-control" value="<?php echo set_value('title',$article->title); ?>" size="50" />
				    	<?php echo form_error('title'); ?>
				    </div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">类别：</label>
				    <div class="col-sm-9">
				    	<select name="catalog_id">
				    		<option value="">请选择一个分类</option>
				    		<?php foreach($catalogs as $catalog){ ?>
				    		<option <?php echo  set_select('catalog_id',$catalog->id,$article->catalog_id==$catalog->id); ?> value="<?php echo $catalog->id ;?>"><?php echo $catalog->name;?></option>
				    		<?php } ?>
				    	</select>
				    	<?php echo form_error('catalog_id'); ?>
				    </div>
			  	</div>
			  	<div class="form-group">
				    <label class="col-sm-2 control-label ">图片：</label>
				    <div class="col-sm-5">
				    	<input type="text" id="img" name="img" class="form-control" value="<?php echo set_value('img',$article->img)?>" size="50" />
				    	<a id="upload" href="#">上传文件</a>
				    	<?php echo form_error('img'); ?>
				    </div>
				    <div class="col-sm-5" id="preview">
				    </div>
			  	</div>
			  	<div class="form-group">
				    <label class="col-sm-2 control-label ">描述：</label>
				    <div class="col-sm-9">
				    	<textarea  name="desc" rows=5 class="form-control"><?php echo set_value('desc',$article->desc); ?></textarea>
				    	<?php echo form_error('desc'); ?>
				    </div>
			  	</div>
			  	<div class="form-group">
				    <label class="col-sm-2 control-label">内容：</label>
				    <div class="col-sm-9">
				    	<textarea id="content" name="content" class="form-control"><?php echo set_value('content',$article->content); ?></textarea>
				    	<?php echo form_error('content'); ?>
				    </div>
			  	</div>
			  	<div class="col-sm-offset-2 col-sm-9">
			  		<input type="submit" value="提交" class="btn btn-success " />
			  		<a class="btn btn-info" href="<?php echo site_url('admin/Article/index') ?>">返回</a>
			  	</div>
			</form>
		</div>
	</div>
</div>
<script type="text/javascript">
	$("#upload").click(function(){
		$.upload({
	        url: '<?php echo site_url("admin/Util/upload"); ?>', 
	        fileName: 'file', 
	        dataType: 'text',
	        onSend: function() {
	                return true;
	        },
	        onComplate: function(data){
	        	if(data.indexOf('upload')>=0){
		        	$("#img").val(data);
		            $("#preview").html('<img style="height:80px;" src="<?php echo base_url().'public/';?>'+data+'" />');	
	        	}else{
	        		alert(data);
	        	}
	        }
		});
	})
</script>
</body>
</html>
